<?php if (!defined('THINK_PATH')) exit();?>﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>选择患者</title>
    <link rel="stylesheet" href="/yilianti/Public/home/js/layui/css/layui.css"/>
    <script src="/yilianti/Public/home/js/layui/layui.js"></script>
    <script src="/yilianti/Public/home/js/jquery.js" type="text/javascript" charset="utf-8"></script>
    <script src="/yilianti/Public/home/js/zepto.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/yilianti/Public/home/js/TouchSlide.1.1.js"></script>
    <script src="/yilianti/Public/home/js/jQuery.textSlider.js"></script>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="/yilianti/Public/home/css/weui.css"/>
    <link rel="stylesheet" href="/yilianti/Public/home/css/myself.css"/>
    <script>
        layui.use('layer', function(){
            var layer = layui.layer;
        });
    </script>
</head>
<body>
<!--

-->


    <input name="page" id="page" type="hidden" value="">
    <div class="weui-cell ">
        <div class=" sele_xial xuanzeyiyuan_sel xuanzehuanzhe_sel ">
            <select class="weui-select " name="cateid" id="select_cate">
                <option value="0">选择疾病类型</option>
                <?php if(is_array($catelist)): foreach($catelist as $key=>$vo): ?><option value="<?php echo ($vo['id']); ?>"><?php echo ($vo['title']); ?></option><?php endforeach; endif; ?>
            </select>
        </div>
        <div class=" sear_rxuanzyy">
            <input type="text" class=" input_border " name="name" id="searchname" placeholder="搜索患者名称">
        </div>
    </div>
    <div class="weui-media-box">
        <a href="/yilianti/index.php/User/patientadd" class="weui-btn tianjia_but patientadd">+ 添加患者</a>
    </div>
    <div class="page__bd">
        <div id="searchResult">
            <!--<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
                <div class="weui-media-box__bd">
                    <div class="fl">
                        <h4 class="weui-media-box__title">标题一</h4>
                        <p class="weui-media-box__desc">由各种物质</p>
                    </div>
                    <div id="" class="fr">
                        <span class="weui-btn weui-btn_mini weui-btn_sel" >选择</span>
                    </div>
                </div>
            </a>-->
        </div>

        <div id="msgshow">
        </div>
        <input type="button" id="more" class="listmore" value="加载更多">
    </div>
    <script type="text/javascript">
        $(function(){
            //默认选中选择的省份和医院名称
            var cateid      = localStorage.getItem('cateid');
            var pname       = localStorage.getItem('pname');
            if(cateid){
                $('#select_cate').val(JSON.parse(cateid));
            }
            if(pname){
                $('#searchname').val(JSON.parse(pname));
            }
            var page = 1;

            patient_list(pname,cateid,page);
            //选择省份
            $("#select_cate").change(function(){
                var cateid = $("#select_cate option:selected").val();
                localStorage.setItem('cateid',JSON.stringify(cateid));
                $("#msgshow").html('');
                patient_list(pname,cateid,page);
            });
            function patient_list(pname,cateid,page){
                $.ajax({
                    type:'post',
                    url:'/yilianti/index.php/Referral/patientlist',
                    data:{name:JSON.parse(pname),cateid:JSON.parse(cateid),page:page},
                    cache:false,
                    dataType:'json',
                    success:function(res){
                        if (res.code == 0) {
                            var arr = res.data;
                            var str = '';
                            $("#searchResult").html('');
                            $.each(arr, function (i) {
                                str += '<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg"><div class="weui-media-box__bd"><div class="fl"><h4 class="weui-media-box__title">' + this.name + '</h4><p class="weui-media-box__desc">' + this.title + '</p> </div><div id="" class="fr"><span class="weui-btn weui-btn_mini weui-btn_sel select_patient" data-id="' + this.id + '" data-pname="' + this.name + '">选择</span> </div></div></a>';
                            });
                            $("#page").val(res.page);
                            $("#searchResult").append(str);
                        } else {
                            var str2 = '';
                            str2 += '<div class="nomore"><p>' + res.msg + '</p></div>';
                            $("#searchResult").html('');
                            $("#searchResult").html(str2);
                            $("#more").hide();
                        }
                    }
                });
            }
            //点击加载更多
            $("#more").click(function(){
                var page = $('#page').val();
                var cateid = $("#select_cate option:selected").val();
                $.ajax({
                    type:'post',
                    url:'/yilianti/index.php/Referral/patientlist',
                    data:{name:JSON.parse(pname),cateid:cateid,page:page},
                    cache:false,
                    dataType:'json',
                    success:function(res){
                        if (res.code == 0) {
                            var arr = res.data;
                            var str = '';
                            $.each(arr, function (i) {
                                str += '<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg"><div class="weui-media-box__bd"><div class="fl"><h4 class="weui-media-box__title">' + this.name + '</h4><p class="weui-media-box__desc">' + this.title + '</p> </div><div id="" class="fr"><span class="weui-btn weui-btn_mini weui-btn_sel select_patient" data-id="' + this.id + '" data-pname="' + this.name + '">选择</span> </div></div></a>';
                            });
                            $("#page").val(res.page);
                            $("#searchResult").append(str);
                        } else {
                            var str2 = '';
                            str2 += '<div class="weui-cell weui-cell_access"><div class="weui-cell__bd weui-cell_primary"><p>' + res.msg + '</p></div></div>';
                            $("#msgshow").html(str2);
                            $("#more").hide();
                        }
                    }
                });
            });
            //变输入医院名称边搜索
            $(document).on('keyup','#searchname',function(){
                var pname   = $(this).val();
                pname       = JSON.stringify(pname);
                localStorage.setItem('pname',pname);
                patient_list(pname,cateid,page);
            });
            //选中医院并返回
            $(document).on('click',".select_patient",function(){
                var pid      = $(this).attr("data-id");
                var pname    = $(this).attr("data-pname");
                var patient  = new Object();
                patient.pid   = pid;
                patient.pname = pname;
                localStorage.setItem('patient',JSON.stringify(patient));
                //referral = JSON.parse(localStorage.getItem('referral'));
                window.location.href = "/yilianti/index.php/Referral/index";
            });
        });
    </script>



    <div class="weui-tabbar">
        <a href="/yilianti/index.php/Index/index" class="weui-tabbar__item weui-bar__item_on">
                <span style="display: inline-block;position: relative;">
                    <img src="/yilianti/Public/home/img/ind_01.png" alt="" class="weui-tabbar__icon">

                </span>
            <p class="weui-tabbar__label">首页</p>
        </a>
        <a href="/yilianti/index.php/Article/index" class="weui-tabbar__item">
            <img src="/yilianti/Public/home/img/ind_02.png" alt="" class="weui-tabbar__icon">
            <p class="weui-tabbar__label">新闻动态</p>
        </a>
        <a href="/yilianti/index.php/Referral/index" class="weui-tabbar__item">
                <span style="display: inline-block;position: relative;">
                    <img src="/yilianti/Public/home/img/ind_03.png" alt="" class="weui-tabbar__icon">

                </span>
            <p class="weui-tabbar__label">会诊转诊</p>
        </a>
        <a href="/yilianti/index.php/User/userlist" class="weui-tabbar__item">
            <img src="/yilianti/Public/home/img/ind_04.png" alt="" class="weui-tabbar__icon">
            <p class="weui-tabbar__label">个人中心</p>
        </a>
    </div>
    <script type="text/javascript">
        $(function(){
            $('.weui-tabbar__item').on('click', function () {
                $(this).addClass('weui-bar__item_on').siblings('.weui-bar__item_on').removeClass('weui-bar__item_on');
            });
        });
    </script>



</body>
</html>